package com.yunao.web.convert;


import com.yunao.entity.Subject;
import com.yunao.web.form.SubjectForm;
import org.apache.commons.lang3.StringUtils;

public class SubjectForm2SubjectConverter {

    public static Subject convert(SubjectForm subjectForm){
        Subject subject = new Subject();
        //区别修改和新建
        if (!StringUtils.isEmpty(subjectForm.getId())) {
            subject.setSubjectId(Integer.parseInt(subjectForm.getId()));
        }
        subject.setParentid(Integer.parseInt(subjectForm.getParentid()));
        subject.setSubjectName(subjectForm.getName());
        subject.setWord(subjectForm.getWord());
        subject.setRemoveWord(subjectForm.getRemoveWord());
        String province = subjectForm.getProvince();
        String city = subjectForm.getCity();
        if (StringUtils.isNotEmpty(province)){
            if (StringUtils.isNotEmpty(city)){
                subject.setSubjectLocaltion(subjectForm.getProvince()+":"+subjectForm.getCity());
            }else {
                subject.setSubjectLocaltion(subjectForm.getProvince());
            }
        }
        subject.setSubjectQuery(subjectForm.getQuery());
        subject.setSubjectType(Integer.parseInt(subjectForm.getType()));
        subject.setUserId(subjectForm.getUserId());
        subject.setOrganId(subjectForm.getOrganId());
        return  subject;

    }


}
